<template>
    <div>
        <Modal
            v-model="confirmErrMsgModal"
            width="800"
            class="col-2"
            :closable="false"
            :mask-closable="false"
        >
            <div slot="header">
                错误消息提示
                <Icon class="f-fr" type="ios-close" @click="closeModal"/>
            </div>
            <Table :columns="columns" :data="dataList" height="400"></Table>
            <div slot="footer">
                <Button type="primary" @click="continueHandle">校验通过</Button>
                <Button type="default" @click="closeModal">取消</Button>
            </div>
        </Modal>
    </div>
</template>

<script>
import { changeConfirmStatus } from '@/api/declare'
import qs from 'qs'

export default {
    name: 'ConfirmErrMsg',

    data () {
        return {
            confirmErrMsgModal: false,
            dataList: [],
            obj: {},
            type: '',
            columns: [
                {
                    title: '内部编号',
                    key: 'relNo',
                    width: 150,
                    tooltip: true
                },
                {
                    title: '表名',
                    key: 'className',
                    width: 150
                },
                {
                    title: '字段名',
                    key: 'fieldName',
                    width: 200,
                    tooltip: true
                },
                {
                    title: '错误级别',
                    key: 'gradeName',
                    width: 100
                },
                {
                    title: '错误原因',
                    key: 'message',
                    width: 450,
                    tooltip: true
                }
            ]
        }
    },
    methods: {
        init (list, obj, type) {
            this.obj = obj
            this.type = type

            list.forEach(item => {
                item.gradeName = item.grade === 'error' ? '错误' : '警告'
            })
            this.dataList = list
            this.confirmErrMsgModal = true
        },

        closeModal () {
            this.confirmErrMsgModal = false
            this.closeModalAfter()
        },

        continueHandle () {
            this.obj.continueFlag = 'Y'
            changeConfirmStatus(qs.stringify(this.obj)).then(res => {
                if (res.data.code === '0000') {
                    this.$Message.success(res.data.msg)
                    this.successAfter()
                    this.confirmErrMsgModal = false
                } else {
                    this.$Message.warning(res.data.msg)
                }
            })
        },

        successAfter () {
            this.$emit('success')
        },
        closeModalAfter () {
            this.$emit('cancel')
        }
    }
}
</script>

<style lang="less">

</style>
